<?php

/**
 * @name ErrorController
 * @desc 错误控制器, 在发生未捕获的异常时刻被调用
 * @see http://www.php.net/manual/en/yaf-dispatcher.catchexception.php
 * @author superx
 */
class ErrorController extends Yaf_Controller_Abstract {

    //从2.1开始, errorAction支持直接通过参数获取异常
    public function errorAction(Exception $exception) {

        if ($this->getRequest()->isXmlHttpRequest()) {
            if ($exception instanceof Core_CatchableException) {
                $this->_view->renderAjax(null, Core_I18N::_($exception->getCode(), 'error'), $exception->getCode());
            } else {
                $this->_view->renderAjax(null, $exception->getMessage(), $exception->getCode());
            }
        } else {
            $this->_view->assign("exception", $exception);
        }
        Core_Log::logErr($exception, 'WEB_ERR');
    }
}
